// pages/school/school.js
const util = require("../../utils/util.js");
const app = getApp()
const baseImgUrl = util.baseImgUrl;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    scanPic:baseImgUrl+"scan_home.png",
    classes:[
      {
        id:0,
        version:"版本",
        listname:[{
          nameid:"01",
          name: "全部",
          tag: 1
        },{
            nameid: "01",
            name: "苏教版",
            tag: 0
          }, {
            nameid: "01",
            name: "全部全部",
            tag: 0
          }]
      },{
        id: 1,
        version: "年级",
        listname: [{
          nameid: "10",
          name: "全部",
          tag:1//默认为0 未选中 选中为1
        }, {
          nameid: "11",
            name: "一年级",
            tag: 0
        }, {
          nameid: "12",
            name: "二年级",
            tag: 0
          }, {
            nameid: "13",
            name: "三年级",
            tag: 0
          }, {
            nameid: "14",
            name: "四年级",
            tag: 0
          }, {
            nameid: "15",
            name: "五年级",
            tag: 0
          }, {
            nameid: "16",
            name: "六年级",
            tag: 0
          }]
      }
    ],
    newestlist: [{
      id: 0,
      picurl: baseImgUrl + "book_ceshi1.png",
      bookname: "小凤仙故事-小知识大世界小知识大世界小凤仙故事-小知识大世界小知识大世界",
      author: "银河老师银河老师银河老师",
      scan: "123600"
    }, {
      id: 1,
      picurl: baseImgUrl + "book_ceshi1.png",
      bookname: "小凤仙故事-小知识大世界",
      author: "银河老师",
      scan: "1236"
    }, {
      id: 2,
      picurl: baseImgUrl + "book_ceshi1.png",
      bookname: "小凤仙故事-小知识大世界",
      author: "银河老师",
      scan: "12360"
    }],
  },
  /********选择分类************* */
  choseNav:function(e){
    console.log(e);
    var arr="";
    var that=this;
      var index=e.currentTarget.dataset.index;
    var subindex = e.currentTarget.dataset.subindex;
    var nameid = e.currentTarget.dataset.nameid;
      console.log(index+"******"+subindex);
    var len = that.data.classes.length;
    console.log("数组长度"+len);
    //循环数组
    for(var i=0;i<len;i++){

      if(index==i){
        var subLen = that.data.classes[i].listname.length;

        for(var j=0;j<subLen;j++){
          that.data.classes[i].listname[j].tag=0;
         }
         that.data.classes[i].listname[subindex].tag=1;
        }
      }
      //循环结束
      that.setData({
        classes: that.data.classes
      })

    for (var i = 0; i < len; i++) {
      var subLen = that.data.classes[i].listname.length;
      for (var j = 0; j < subLen; j++) {
        if (that.data.classes[i].listname[j].tag ==1){
          arr+= that.data.classes[i].listname[j].nameid+"|";
        }
      }
    }
      console.log("选中的id"+arr);
      
   
  },
  //点击视频
  audiodetail: function (e) {
    console.log(e);
    var that = this;
    var newid = e.currentTarget.dataset.id;
    var index_now = e.currentTarget.dataset.index;
    // that.data.newestlist[index_now].hasread = 1;
    // that.setData({
    //   newestlist: that.data.newestlist
    // })
    wx.navigateTo({
      url: '/pages/audioDetail/audioDetail?newid=' + newid,
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})